<script>
    var page_list = "columnExt_list";
    $(function() {
        $("body").layout();
        grid_init($("#grid"),{
            singleSelect: false,
            columns:[[
                { field: 'o.id', checkbox: true, title: 'ID',width: 80},
                { field: 'o.companyName', title: '公司名称',width: 200},
                { field: 'o.columnKey', title: '字段名称',width: 300},
                { field: 'o.defaultValue', title: '字段默认值',width: 120},
                { field: 'o.remark', title: '备注',width: 150},
                { field: 'o.useFlag', title: '是否启用',width: 100,formatter: function(value,row,index){
                    if (value=="1"){
                        return "禁用";
                    } else if(value=="0"){
                        return "启用";
                    }
                    return value;
                }},
                { field: 'o.type', title: '显示页面',width: 150,formatter: function(value,row,index){
                    if (value=="0"){
                        return "下单";
                    } else if(value=="1"){
                        return "取款";
                    }
                    return value;
                }},

                { field: 'u.realName', title: '创建人',width: 80},
                { field: 'o.createTime', title: '创建时间',width: 150}]],
            _order:"o.createTime desc",
            _append: [],//隐藏列
            _page: page_list,
            _table: "bs_column_ext as o left join bs_user as u on o.createBy = u.id " ,
            _exportTitle: false,//不打印
            _context_handle: [{
                text: "详情",
                icon: "icon-info",
                handle: function(index,row){
                    j_showWin({url:'logistics/columnExt/info.html?keyId='+this.getFieldValue(row,"o.id"),
                        title:'字段扩展',
                        iconCls: 'icon-form-info'})
                }
            },{
                text: "编辑",
                //auth: "update",
                icon: "icon-edit",
                handle: function(index,row){
                    j_showWin({url:'logistics/columnExt/edit.html?keyId='+this.getFieldValue(row,"o.id"),title:'编辑字段扩展信息',iconCls: 'icon-form-edit'})
                }
            },{
                //auth: "delete",
                formatter:function (row) {
                    var useFlag = this.getFieldValue(row,"o.useFlag");
                    if (useFlag == 0){
                        return {text: "禁用",icon: "icon-config-delete"}
                    }else{
                        return {text: "启用",icon: "icon-check"}
                    }
                    return undefined;
                },
                handle: function(index,row){
                    var grid = $(this);
                    var self = this;
                    if(self.getFieldValue(row,"o.useFlag") == 0){
                        $.messager.confirm('系统提示', '您确认禁用该字段扩展信息吗?', function(r){
                            if (r){
                                self.focus();
                                showLoading();
                                fy_api.ajax({
                                    url: "columnExt/delete.do?_t="+new Date().getTime(),
                                    data: {"keyId":self.getFieldValue(row,"o.id"), "useFlag":1 },
                                    success: function(data){
                                        hideLoading();
                                        if(isSuccess(data)){
                                            j_tip(data.msg,'success');
                                            grid.datagrid("reload");
                                        }else{
                                            $.messager.alert('系统提示',data.msg,'error',function(){
                                                self.focus();
                                            });
                                        }
                                    }
                                });
                            }else{
                                self.focus();
                            }
                        });
                    }else{
                        /* j_tip("该字段扩展信息已经是禁用状态",'error'); */
                        $.messager.confirm('系统提示', '您确认启用该字段扩展信息吗?', function(r){
                            if (r){
                                self.focus();
                                showLoading();
                                fy_api.ajax({
                                    url: "columnExt/delete.do?_t="+new Date().getTime(),
                                    data: {"keyId":self.getFieldValue(row,"o.id"), "useFlag":0 },
                                    success: function(data){
                                        hideLoading();
                                        if(isSuccess(data)){
                                            j_tip(data.msg,'success');
                                            grid.datagrid("reload");
                                        }else{
                                            $.messager.alert('系统提示',data.msg,'error',function(){
                                                self.focus();
                                            });
                                        }
                                    }
                                });
                            }else{
                                self.focus();
                            }
                        });
                    }
                }
            },{
                text: "删除",
                //auth: "delete",
                icon: "icon-config-delete",
                handle: function(index,row){
                    var grid = $(this);
                    var self = this;

                    $.messager.confirm('系统提示', '您确认删该字段扩展信息吗?', function(r){
                        if (r){
                            self.focus();
                            showLoading();
                            fy_api.ajax({
                                url: "columnExt/deleteColumnExt.do?_t="+new Date().getTime(),
                                data: {"keyId":self.getFieldValue(row,"o.id")},
                                success: function(data){
                                    hideLoading();
                                    if(isSuccess(data)){
                                        j_tip(data.msg,'success');
                                        grid.datagrid("reload");
                                    }else{
                                        $.messager.alert('系统提示',data.msg,'error',function(){
                                            self.focus();
                                        });
                                    }
                                }
                            });
                        }else{
                            self.focus();
                        }
                    });
                }
            }],
            toolbar: '#grid_toolbar',
            searchDiv: '#grid_search'
        });
        $("input").blur();
        $("#btnBatchDelete").click(function(){
            initBatchOperation(grid_get("grid"),"columnExt/batchDelete.do","禁用");
        })
    });

    //用户列表
    $('#user').inputgrid({
        idField:'o.id',
        textField:'o.loginName',
        searchField:['o.id','o.loginName'],//查询字段多字段匹配
        columns:[[
            { field: 'o.id', title: '员工编号'},
            { field: 'o.loginName', title: '员工姓名'},
            { field: 'o.realName', title: '真实姓名'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "bs_user as o"
    });

    //金融代码
    $('#company').inputgrid({
        idField:'o.id',
        textField:'o.name',
        searchField:['o.code','o.name'],//查询字段多字段匹配
        columns:[[
            { field: 'o.id', title: 'ID'},
            { field: 'o.code', title: '金融代码'},
            { field: 'o.name', title: '名称'},
            { field: 'o.address', title: '地址'}
        ]],
        _page: parent.page_list,
        _append: [],//隐藏列
        _table: "company as o",
        _db:"slave"
    });
</script>
<style>
    .datagrid-cell, .datagrid-cell-group, .datagrid-header-rownumber, .datagrid-cell-rownumber
    {
        text-overflow: ellipsis;
    }
</style>
<div id="grid_search" data-options="region:'north',height:'auto',hideExpandTool: true,hideCollapsedContent: false,collapsedContent:function(){return '查询条件(已隐藏)'}" style="border-top:none;border-left:none;border-right:none;" class="search-form">
    <div class="div-item">
        <div class="div-label">公司名称：</div>
        <input name="o.companyId" type="hidden" clear/>
        <input type="text" id="company" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">字段名称：</div>
        <input type="text" name="o.columnKey" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">字段默认值：</div>
        <input type="text" name="o.defaultValue" clear/>
    </div>
    <div class="div-item">
        <div class="div-label">创建人：</div>
        <input type="hidden" id="createBy" name="o.createBy" clear/>
        <input type="text" id="user" clear/>
    </div>
    <div class="div-item">
        <div class="div-label" style="width: 80px;">状态：</div>
        <select name="o.useFlag" id="useFlag" style="width: 60px;" value="${useFlag}" clear>
            <option value="" >所有</option>
            <option value="0" >启用</option>
            <option value="1" >禁用</option>
        </select>
    </div>

</div>
<div data-options="region:'center',title:false,border:false" id="divCenter" style="">
    <table id="grid"></table>
</div>
<div id="grid_toolbar" style="padding:3px;">
    <a href="javascript:void(0)" class="easyui-linkbutton <!--auth-button-->" action="add" data-options="plain:true,iconCls:'icon-config-add'" onclick="j_showWin({url:'logistics/columnExt/edit.html',title:'添加字段扩展',iconCls: 'icon-form-add'})">添加</a>
    <a href="javascript:void(0)" class="easyui-linkbutton <!--auth-button-->" action="delete" data-options="plain:true,iconCls:'icon-config-delete'" id="btnBatchDelete">批量禁用</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'layout-button-up'" onclick="var button=$(this);if(button.linkbutton('options').iconCls=='layout-button-up'){$('body').layout('collapse','north');button.linkbutton({iconCls:'layout-button-down'})}else{$('body').layout('expand','north');button.linkbutton({iconCls:'layout-button-up'})}button.linkbutton('disable');setTimeout(function(){button.linkbutton('enable');},200)" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-help'" id="help" style="float:right"></a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-button-refresh'" onclick="grid_get('grid')[0].search(true)" style="float:right">重置</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-search'" onclick="grid_get('grid')[0].search()" style="float:right">查询</a>
</div>